package front_shop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

import interface1.Admin;


@SuppressWarnings("serial")
public class administrator extends JFrame implements ActionListener{
	String username,userpassword;
	JLabel title=new JLabel("管理员登录");
	JLabel user_name=new JLabel("用户名");
	JLabel user_password=new JLabel("密 码");
	JTextField name=new JTextField(10);
	JPasswordField password=new JPasswordField(10) ;
	JButton login=new JButton("登录");
	JButton cancel=new JButton("取消");
	JPanel panel=new JPanel();
	administrator(){
		add(panel);
		panel.setLayout(null);
		panel.add(title);
		panel.add(user_name);
		panel.add(user_password);
		panel.add(name);
		panel.add(password);
		panel.add(login);
		panel.add(cancel);
		password.setEchoChar('*');//设置密码框回显字符
		title.setBounds(140,40,100,30);
		user_name.setBounds(100,80,50,30);
		name.setBounds(160,80,100,30);
		user_password.setBounds(100,120,50,30);
		password.setBounds(160,120,100,30);
		login.setBounds(50,200,100,30);
		cancel.setBounds(220,200,100,30);
		login.addActionListener(this);
		cancel.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e){
		char p[];
		if (e.getSource()==login){
			username=name.getText();
			p=password.getPassword();
			userpassword=new String(p);
			if (username.equals(""))
			{
				JOptionPane.showMessageDialog(this,"请输入用户名！！！","管理员登录",JOptionPane.WARNING_MESSAGE);
				name.requestFocus();
			}
			else if(userpassword.equals("")){
				JOptionPane.showMessageDialog(this,"请输入密码！！！","管理员登录",JOptionPane.WARNING_MESSAGE);
				password.requestFocus();

			}
			
			else if  (! username.equals("admin")){
				JOptionPane.showMessageDialog(this,"该用户不存在！！！","管理员登录",JOptionPane.WARNING_MESSAGE);
				name.setText("");
				name.requestFocus();
				

			 }
			else if (!userpassword.equals("123456")){
				JOptionPane.showMessageDialog(this,"密码不正确！！！","管理员登录",JOptionPane.WARNING_MESSAGE);
				password.setText("");
				password.requestFocus();
			}
			else {
				JOptionPane.showMessageDialog(this,"登录成功","管理员登录",JOptionPane.WARNING_MESSAGE);
				Admin admin = new Admin();  // new 后台， 即可转到后台
				
				this.dispose();
			}
			
		}
		if (e.getSource()==cancel){
			this.dispose();
		}
	}
/*	public static void main(String[] args) {
		// TODO Auto-generated method stub
		administrator frame=new administrator();
		frame.setTitle("管理员登录 ");
		frame.setBounds(100,100,360,300);
		frame.setVisible(true);
		frame.validate();
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		}
		*/
}

